#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <string.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/shm.h>
#define SIZE 100
#define GOODS_NUM 10
#define STORAGE_NUM 5

int main(int argc, char *argv[])
{
	int key,key2;
	int msgid;
	int /*msgid2,*/semid,shmid;
	if(1 != argc)
	{
		printf("Usage: %s <type> <data>\n", argv[0]);
		return -1;
	}
	
	if((key = ftok("/app", 'g')) < 0)
	{
		perror("ftok");
		return -1;
	}
	printf("key:%d\n",key);

	if((key2 = ftok("/app", 'i')) < 0)
	{
		perror("ftok");
		return -1;
	}
	printf("key2:%d\n",key2);

	if((semid  = semget(key2, 1, 0666)) < 0)
	{
		perror("semget");
		exit(1);
	}

	printf("get semid:%d\n",semid);
	shmid = shmget(key2, 320, 0666);
	if(-1 == shmid)
	{
		perror("shmget");
		return -1;
	}
	printf("get shmid:%d\n",shmid);
	
/*	msgid2 = msgget(key2, 0666);
	if(-1 == msgid2)
	{
		perror("msgid2");
		return -1;
	}
	printf("get msgid2:%d\n",msgid2);
*/

	msgid = msgget(key, 0666);
	if(-1 == msgid)
	{
		perror("msgid");
		return -1;
	}

	printf("get msgid:%d\n",msgid);
	
	msgctl(msgid,IPC_RMID,0);
//	msgctl(msgid2,IPC_RMID,0);
	semctl(semid,IPC_RMID,0);
	shmctl(shmid,IPC_RMID,0);
	return 0;
}
